home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / libgutil / rctgl.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  148 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *    rctgl -
  19.  *        GL code for management of rectangles.
  20.  *
  21.  *                Paul Haeberli - 1986
  22.  */
  23. #include "gl.h"
  24. #include "rct.h"
  25. #include "port.h"
  26.  
  27. rctrdraw(r,iradius)
  28. rct *r;
  29. int iradius;
  30. {
  31.     float delx, dely;
  32.     float partx, party;
  33.     float radius;
  34.  
  35.     radius = iradius;
  36.     if(radius<0)
  37.     radius = 0;
  38.     delx = r->xmax-r->xmin;
  39.     dely = r->ymax-r->ymin;
  40.     if(radius > delx)
  41.     radius = delx;
  42.     if(radius > dely)
  43.     radius = dely;
  44.     partx = delx - radius;
  45.     party = dely - radius;
  46.     pushmatrix();
  47.       scale(0.5,0.5,1.0);
  48.       translate((float)r->xmin+r->xmax,(float)r->ymin+r->ymax,0.0);
  49.       pushmatrix();
  50.         translate(-partx,-party,0.0);
  51.         scale(radius,radius,1.0);
  52.     arc(0.0,0.0,1.0,1800,2700);
  53.       popmatrix();
  54.       move2(-partx,-dely);
  55.       draw2( partx,-dely);
  56.       pushmatrix();
  57.         translate( partx,-party,0.0);
  58.         scale(radius,radius,1.0);
  59.     arc(0.0,0.0,1.0,2700,3600);
  60.       popmatrix();
  61.       move2( delx,-party);
  62.       draw2( delx, party);
  63.       pushmatrix();
  64.         translate( partx, party,0.0);
  65.         scale(radius,radius,1.0);
  66.     arc(0.0,0.0,1.0,0,900);
  67.       popmatrix();
  68.       move2( partx, dely);
  69.       draw2(-partx, dely);
  70.       pushmatrix();
  71.         translate(-partx, party,0.0);
  72.         scale(radius,radius,1.0);
  73.     arc(0.0,0.0,1.0,900,1800);
  74.       popmatrix();
  75.       move2(-delx, party);
  76.       draw2(-delx,-party);
  77.     popmatrix();
  78. }
  79.  
  80. rctrfill(rr,iradius)
  81. rct *rr;
  82. int iradius;
  83. {
  84.     int delx, dely;
  85.     float partx, party;
  86.     float radius;
  87.     rct *r, *fr;
  88.  
  89.     if(iradius<0)
  90.     iradius = 0;
  91.     r = rctclone(rr);
  92.     delx = r->xmax-r->xmin;
  93.     dely = r->ymax-r->ymin;
  94.     if(iradius > delx)
  95.     iradius = delx;
  96.     if(iradius > dely)
  97.     iradius = dely;
  98.     partx = delx - iradius;
  99.     party = dely - iradius;
  100.     radius = iradius - 0.4;
  101.     pushmatrix();
  102.       scale(0.5,0.5,1.0);
  103.       translate((float)r->xmin+r->xmax,(float)r->ymin+r->ymax,0.0);
  104.  
  105.       fr = rctnew();
  106.       rctset(fr,(int)-partx,-dely,(int)partx,dely);
  107.       rctfill(fr);
  108.       rctset(fr,-delx,(int)-party,delx,(int)party);
  109.       rctfill(fr);
  110.       rctfree(fr);
  111.  
  112.       pushmatrix();
  113.         translate(-partx,-party,0.0);
  114.         scale(radius,radius,1.0);
  115.     arcf(0.0,0.0,1.0,1800,2700);
  116.       popmatrix();
  117.       pushmatrix();
  118.         translate(partx,-party,0.0);
  119.         scale(radius,radius,1.0);
  120.     arcf(0.0,0.0,1.0,2700,3600);
  121.       popmatrix();
  122.       pushmatrix();
  123.         translate(partx,party,0.0);
  124.         scale(radius,radius,1.0);
  125.     arcf(0.0,0.0,1.0,0,900);
  126.       popmatrix();
  127.       pushmatrix();
  128.         translate(-partx,party,0.0);
  129.         scale(radius,radius,1.0);
  130.     arcf(0.0,0.0,1.0,900,1800);
  131.       popmatrix();
  132.     popmatrix();
  133.     rctfree(r);
  134. }
  135.  
  136. rctdraw(r)
  137. rct *r;
  138. {
  139.     drawrect((float)r->xmin,(float)r->ymin,(float)r->xmax,(float)r->ymax);
  140. }
  141.  
  142. rctfill(r)
  143. rct *r;
  144. {
  145.     fillrect((float)r->xmin,(float)r->ymin,(float)r->xmax,(float)r->ymax);
  146. }
  147.  
  148.